<?php

namespace app\model;
use think\Model;

class ConfigModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'bus_config';
    // 设置当前模型的数据库连接
    protected $connection = 'mysql';

    public static function getConfigArray($groups, $name)
    {
        $config_where = [
            'deleted' => 0,
//            'tenant_id' => 1,
            'groups'=>$groups,
            'name'=>$name,
        ];
        // json格式 statuss = true
        $config = self::where($config_where)
//            ->json(['content'])
//            ->whereRaw("JSON_EXTRACT(content, '$.statuss') = true")
            ->order('listorder', 'asc')
            ->select();

        // 如果不为空 循环 把content字段 转成json
        if(!empty($config)){
            foreach ($config as $key => $value) {
                $config[$key]['content'] = json_decode($value['content'], true);
            }
        }

        return $config;
    }
}